<template>
  <div class="activity-card">
    <div class="card-header">
      <div class="activity-category">{{ activity.categoryName }}</div>
      <div class="activity-status" :class="getStatusClass(activity.status)">
        {{ getStatusText(activity.status) }}
      </div>
    </div>
    <div class="card-body">
      <h3 class="activity-title">{{ truncateTitle(activity.title, 20) }}</h3>
      <p class="activity-description">{{ truncateText(activity.description, 60) }}</p>
      <div class="activity-info">
        <div class="info-item">
          <el-icon><calendar /></el-icon>
          <span>{{ formatDate(activity.startTime) }}</span>
        </div>
        <div class="info-item">
          <el-icon><location /></el-icon>
          <span>{{ truncateText(activity.location, 15) }}</span>
        </div>
      </div>
      <div class="activity-stats">
        <div class="stat-item">
          <el-icon><user /></el-icon>
          <span>{{ activity.participantCount || 0 }}人报名</span>
        </div>
        <div class="stat-item">
          <el-icon><star /></el-icon>
          <span>{{ activity.score || 0.0 }}</span>
        </div>
      </div>
    </div>
    <div class="card-footer">
      <router-link :to="'/activity/' + activity.id" class="view-details">
        查看详情
      </router-link>
    </div>
  </div>
</template>

<script>
import { formatDate, truncateText, mapStatusToFrontend } from '../utils/common'
import { Calendar, Location, User, Star } from '@element-plus/icons-vue'

export default {
  name: 'ActivityCard',
  components: {
    Calendar,
    Location,
    User,
    Star
  },
  props: {
    activity: {
      type: Object,
      required: true
    }
  },
  methods: {
    formatDate(date) {
      return formatDate(date, 'MM-DD HH:mm')
    },
    truncateText(text, maxLength) {
      return truncateText(text, maxLength)
    },
    truncateTitle(text, maxLength) {
      return truncateText(text, maxLength)
    },
    getStatusText(status) {
      const mappedStatus = mapStatusToFrontend(status)
      const statusMap = {
        'DRAFT': '草稿',
        'PUBLISHED': '已发布',
        'ONGOING': '进行中',
        'ENDED': '已结束',
        'CANCELLED': '已取消'
      }
      return statusMap[mappedStatus] || '未知'
    },
    getStatusClass(status) {
      const mappedStatus = mapStatusToFrontend(status)
      const classMap = {
        'DRAFT': 'status-draft',
        'PUBLISHED': 'status-published',
        'ONGOING': 'status-ongoing',
        'ENDED': 'status-ended',
        'CANCELLED': 'status-cancelled'
      }
      return classMap[mappedStatus] || ''
    }
  }
}
</script>

<style scoped>
.activity-card {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  overflow: hidden;
  transition: transform 0.3s, box-shadow 0.3s;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.activity-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

.card-header {
  padding: 12px 16px;
  background: #f5f7fa;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.activity-category {
  font-size: 12px;
  color: #606266;
  background: #e4e7ed;
  padding: 2px 8px;
  border-radius: 4px;
}

.activity-status {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 500;
}

.status-draft {
  background: #e4e7ed;
  color: #909399;
}

.status-published {
  background: #ecf5ff;
  color: #409eff;
}

.status-ongoing {
  background: #f0f9ff;
  color: #67c23a;
}

.status-ended {
  background: #f5f7fa;
  color: #909399;
}

.status-cancelled {
  background: #fef0f0;
  color: #f56c6c;
}

.card-body {
  padding: 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.activity-title {
  font-size: 16px;
  font-weight: 600;
  color: #303133;
  margin-bottom: 8px;
  line-height: 1.4;
}

.activity-description {
  font-size: 14px;
  color: #606266;
  line-height: 1.6;
  margin-bottom: 12px;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.activity-info {
  margin-bottom: 12px;
}

.info-item {
  display: flex;
  align-items: center;
  font-size: 13px;
  color: #909399;
  margin-bottom: 6px;
}

.info-item .el-icon {
  margin-right: 6px;
  font-size: 14px;
}

.activity-stats {
  display: flex;
  justify-content: space-between;
  padding-top: 12px;
  border-top: 1px solid #f0f0f0;
}

.stat-item {
  display: flex;
  align-items: center;
  font-size: 13px;
  color: #606266;
}

.stat-item .el-icon {
  margin-right: 4px;
  font-size: 14px;
}

.card-footer {
  padding: 16px;
  border-top: 1px solid #f0f0f0;
  text-align: center;
}

.view-details {
  display: inline-block;
  color: #409eff;
  text-decoration: none;
  font-size: 14px;
  transition: color 0.3s;
}

.view-details:hover {
  color: #66b1ff;
}
</style>